<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 1.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
* Ineo - Modules - Categories
*  
* This module handles all front-end actions related to articles.
*
* @package		Ineo
* @subpackage   Modules
* @author		Dan Cryer & William McGann
* @copyright	Dan Cryer & William McGann
* @version		1.0.0
*/
class ineo_mod_category
{
    var $ipsclass;
    var $core;
    
    /**
    * Initialize class:
    */
    function module_init()
    {
        $this->lib_cat =& $this->core->load_library('categories');
		$this->core->load_template('categories');
		$this->core->load_template('articles');
    }
    
    /**
    * Generate and display a list of categories:
    */
    function catlist()
	{
		// Use category library to get an array of categories ( with parent 0 ).
		$categories = $this->lib_cat->load_cats_by_parent(0);
				
		$list = '';
		
		$this->core->title .= ' - ' . $this->ipsclass->lang['ams_categories'];
		
		// Loop & build list:
		foreach( $categories as $cat )
		{
			$list .= $this->core->templates['categories']->cat_row( $cat );
		}
		
		// Output list using main template:
		$this->core->out .= $this->core->templates['categories']->cat_index( $list , $this->ipsclass->lang['ams_categories'] );
	}
	
	/**
	* Display a category:
	*/
	function cat()
	{
	  	$catId = intval($this->ipsclass->input['id']);
		
		// Load category data:
    	$cat = $this->lib_cat->load_category_data( $catId );
	
		// Use category library to get an array of categories ( with parent {ID} ).
		$categories = $this->lib_cat->load_cats_by_parent($catId);
		
		// Setup category options block
		$this->core->menu_block( 'ams_this_cat' );
		// Do the options section
		$this->core->menu_block_section( 'ams_catopts' , array( 'ams_cat_watch' => 'mod=global&op=watch_add_cat&id='.$catId ) );
		// Add the thing already!
		$this->core->menu_add_block();
			
		$list = '';
			
		if( is_array($categories) )	
		{
			// Has cats! Meow.
			$has_cats = true;
			
			// Loop & build list:
			foreach( $categories as $sub )
			{
				$list .= $this->core->templates['categories']->cat_row( $sub );
			}
			
			// Output list using main template:
			$this->core->out .= $this->core->templates['categories']->cat_index( $list , $cat['category_name'] );
		}
		else
		{
			$has_cats = false;
		}
		
	    
		$this->core->title .= ' - ' . $cat['category_name'];
		$this->core->nav_add( $cat['category_name'] , 'showcat=' . $catId );
		
		$this->core->out .= "<div id='category-articles-div'>";
		$this->core->out .= $this->lib_cat->display_article_list( $catId, $cat , 'article_id DESC' );
		$this->core->out .= '</div>';
	}
}

?>